<?php
/**
* @package Frontend-User-Access (com_frontenduseraccess)
* @version 3.0.8
* @copyright Copyright (C) 2008 Carsten Engel. All rights reserved.
* @license GPL versions free/trial/pro
* @author http://www.pages-and-items.com
* @joomla Joomla is Free Software
*/

// no direct access
defined('_JEXEC') or die('Restricted access');

if(!$this->controller->fua_config['display_menuaccess'] && $this->controller->user_type!='Super Administrator'){
	die('Restricted access');
}

//header and nav
$this->controller->echo_header();

?>

<script language="javascript" type="text/javascript">

<?php


//make javascript arrays from menuItems per menutype
for($n = 0; $n < count($this->menu_types); $n++){
	$javascript_menu = 'var menuarray_'.$this->menu_types[$n][0].' = new Array(';
	$first = true;
	foreach($this->fua_menu_items as $page){
		$page_menu_type = str_replace('-','separator',$page->menutype);	
		if($page_menu_type==$this->menu_types[$n][0]){
			if($first){
				$first = false;
			}else{
				$javascript_menu .= ',';
			}
			$javascript_menu .= '"'.$page->id.'"';
		}
	}
	$javascript_menu .= ');';
	echo $javascript_menu."\n";
}

//make javascript array from usergroups
$javascript_array_usergroups = 'var usergroups = new Array(';
$first = true;
foreach($this->fua_usergroups as $usergroup){
	if($first){
		$first = false;
	}else{
		$javascript_array_usergroups .= ',';
	}
	$javascript_array_usergroups .= '"'.$usergroup->id.'"';
}
$javascript_array_usergroups .= ');';
echo $javascript_array_usergroups."\n";

?>

function toggle_right(hidden_field_id){
	field = document.getElementById(hidden_field_id);
	if(field.value==hidden_field_id+'__1'){
		field.value = hidden_field_id+'__';
	}else{
		field.value = hidden_field_id+'__1';
	}
}

function select_all(menutype_array_name, usergroup_id, select_all_id){
	action = document.getElementById(select_all_id).checked;	
	pages = eval(menutype_array_name);	
	for (i = 0; i < pages.length; i++){
		box_id = pages[i]+'_0_'+usergroup_id;
		hidden_id = pages[i]+'__'+usergroup_id+'__hidden';		
		if(action==true){
			//alert(box_id);
			document.getElementById(box_id).checked = true;
			document.getElementById(hidden_id).value = hidden_id+'__1';
		}else{
			document.getElementById(box_id).checked = false;
			document.getElementById(hidden_id).value = hidden_id+'__';
		}
	}	
}

</script>
<form name="adminForm" method="post" action="">
	<input type="hidden" name="option" value="com_frontenduseraccess" />
	<input type="hidden" name="task" value="" />
	<?php echo JHTML::_( 'form.token' ); ?>	
<table id="fua_subheader">
	<tr>
		<td>
			<?php 
				echo '<p>'.JText::_('MENU_INFO2').'.</p>';				
				
				if(!file_exists(dirname(__FILE__).'/../../../../../../modules/mod_frontenduseraccessmenu/mod_frontenduseraccessmenu.php')){	
					echo '<p style="color: red;">'.JText::_('MODULE_NOT_INSTALLED').'.</p>';			
				}

				//legend and message if reverse access	
				$this->controller->reverse_access_warning('menu_reverse_access');
				
				//message in free version that these restrictions will not work in free version
				$this->controller->not_in_free_version();
				
				//message if item access is not activated		
				if($this->controller->fua_config['use_menuaccess']==false){				
					echo '<div style="color: red; text-align: left;">'.JText::_('NO_ACTIVE_MENU').'. <a href="index2.php?option=com_frontenduseraccess&view=config&tab=menu_access">'.JText::_('ACTIVATE_IN_CONFIG').'</a><br/><br/></div>';
				}		
						
			?>
		</td>
		<td id="td_usergroup_selector">
			<?php echo $this->controller->usergroup_selector(); ?>
		</td>
	</tr>
</table>			
<table class="adminlist">
	<tr>		
		<th>&nbsp;
						
		</th>
		<?php
		
			if($this->controller->fua_config['display_joomla_access_levels']){
				echo '<th>&nbsp;</th>';
			}			
			$this->controller->loop_usergroups($this->fua_usergroups);			
		?>
	</tr>
		
	<?php
	
if($this->controller->fua_config['display_joomla_access_levels']){
	$colspan = count($this->fua_usergroups)+1;
	echo '<tr>';
	echo '<td>&nbsp;</td>';
	echo '<td>';
	echo '<span class="editlinktip" onmouseover="return overlib(\''.addslashes(JText::_('JOOMLA_ACCESS_LEVELS_INFO')).'.\', CAPTION, \''.addslashes(JText::_('JOOMLA_ACCESS_LEVELS')).'\', BELOW, RIGHT, WIDTH, 400);" onmouseout="return nd();" >';
	echo JText::_('JOOMLA_ACCESS_LEVELS');
	echo '</span>';
	echo '</td>';
	echo '<td colspan="'.$colspan.'">&nbsp;</td>';
	echo '</tr>';
}		
							
$this->model->fua_page_access_init($this->fua_usergroups, $this->controller->fua_config, $this->fua_menu_items, $this->access_menuitems);
$this->model->fua_echo_menus();

?>	
</table>
</form>
<?php

$this->controller->display_footer();

?>